use std::path::{Path, PathBuf};

fn exists(path: impl AsRef<Path>) -> bool {
    PathBuf::from(path.as_ref()).exists()
}

extern crate bindgen;

fn main() { 
 
    let lib = if cfg!(unix) {
        if exists("/usr/lib/quickjs/libquickjs.a") {
            "/usr/lib/quickjs"
        } else if exists("/usr/local/lib/quickjs") {
            "/usr/local/lib/quickjs"
        } else {
            panic!("quicks is not supported on this platform");
        }
    } else {
        return
    };
    /*
    // Generate bindings.
    let bindings = bindgen::Builder::default()
        .header("wrapper.h")
        .generate()
        .expect("Unable to generate bindings");

    // Write the bindings to the $OUT_DIR/bindings.rs file.
    let out_path = env::current_dir().unwrap();
    //dbg!(&out_path);
    bindings
        .write_to_file(out_path.join("bindings.rs"))
        .expect("Couldn't write bindings!");
    //dbg!(&out_path);
    */
    // Instruct cargo to statically link quickjs.
    println!("cargo:rustc-link-search=native={}", lib);
    println!("cargo:rustc-link-lib=static=quickjs");
}
